package com.ll.generic;

import java.util.*;

/**
 * @author 刘龙
 * @version 1.0
 */
public class Generic02 {
    public static void main(String[] args) {

        ArrayList arrayList1 = new ArrayList();
        ArrayList<Object> arrayList2 = new ArrayList<Object>();
        List<Integer> list = new ArrayList<>();
        HashSet<Student> students = new HashSet<>();
        students.add(new Student("ll", 20));
        students.add(new Student("ll2", 22));

        // 1
        for (Student student : students) {
            System.out.println(student);
        }

        // 2
        Iterator<Student> iterator = students.iterator();
        while (iterator.hasNext()) {
            Student student =  iterator.next();
            System.out.println(student);
        }

        System.out.println("================================================");

        HashMap<String, Student> stringStudentHashMap = new HashMap<>();
        stringStudentHashMap.put("111", new Student("ll", 20));
        stringStudentHashMap.put("222", new Student("ll2", 22));

        // 1
        Set<String> strings = stringStudentHashMap.keySet();
        for (String string : strings) {
            System.out.println(string + " " + stringStudentHashMap.get(string));
        }

        // 2
        Iterator<String> iterator1 = strings.iterator();
        while (iterator1.hasNext()) {
            String string = iterator1.next();
            System.out.println(string + " " + stringStudentHashMap.get(string));
        }

        // 3
        Set<Map.Entry<String, Student>> entries = stringStudentHashMap.entrySet();
        Iterator<Map.Entry<String, Student>> iterator2 = entries.iterator();
        while (iterator2.hasNext()) {
            Map.Entry<String, Student> next = iterator2.next();
            System.out.println(next.getKey() + "-" + next.getValue());
        }
    }
}

class Student {
    private String name;
    private int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}


